package cn.ustb.serviceImpl;

import cn.ustb.dao.StudentOptCourseDao;
import cn.ustb.entity.StudentOptCourse;
import cn.ustb.service.StudentOptCourseService;
import cn.ustb.util.MyBatisUtil;
import org.apache.ibatis.session.SqlSession;


/**
 * @author yuyan
 */
public class StudentOptCourseServiceImpl implements StudentOptCourseService {
    @Override
    public StudentOptCourse get(StudentOptCourse studentOptCourse) {
        SqlSession sqlSession=null;
        try{
            sqlSession = MyBatisUtil.getInstance();
            StudentOptCourseDao studentOptCourseDao = sqlSession.getMapper(StudentOptCourseDao.class);
            return studentOptCourseDao.getByStudentIdandCourseId(studentOptCourse);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if (sqlSession!=null){
                sqlSession.close();
            }
        }
        return null;
    }

    @Override
    public void insert(StudentOptCourse studentOptCourse) {
        SqlSession sqlSession=null;
        try{
            sqlSession = MyBatisUtil.getInstance();
            StudentOptCourseDao studentOptCourseDao = sqlSession.getMapper(StudentOptCourseDao.class);
            studentOptCourseDao.insert(studentOptCourse);

            sqlSession.commit();
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            if (sqlSession!=null){
                sqlSession.close();
            }
        }
    }
}
